import {baseWS} from './config'
export default {
    ws: {},
    initWs: function(userId){
        this.ws = new WebSocket(baseWS + "/question/"+userId);
        this.ws.onopen = function(){console.log('连接成功');}
        this.ws.onclose = function(){console.log('连接关闭');}
    },
    setWs: function(newWs) {
        this.ws = newWs
    },
    send: function(message){
        this.ws.send(message)
    },
    close: function(){
        this.ws.close()
    },
    sleep: function(time){
        return new Promise(resolve => {
            setTimeout(resolve, time)
        })
    }
}
